home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
stdio
/
RCS
/
fputc.c,v
< prev
next >
Wrap
Text File
|
1991-12-02
|
4KB
|
147 lines
head 1.2;
branch ;
access ;
symbols sprited:1.2.1;
locks ; strict;
comment @ * @;
1.2
date 88.07.21.10.49.10; author ouster; state Exp;
branches 1.2.1.1;
next 1.1;
1.1
date 88.06.10.16.23.47; author ouster; state Exp;
branches ;
next ;
1.2.1.1
date 91.12.02.19.57.20; author kupfer; state Exp;
branches ;
next ;
desc
@@
1.2
log
@Return the character written, not 0.
@
text
@/*
* fputc.c --
*
* Source code for the "fputc" library procedure.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: fputc.c,v 1.1 88/06/10 16:23:47 ouster Exp $ SPRITE (Berkeley)";
#endif not lint
#include "stdio.h"
/*
*----------------------------------------------------------------------
*
* fputc --
*
* This procedure outputs a character onto a stream. It is a
* procedural version of the putc macro, and also gets
* called by putc when the output buffer has filled.
*
* Results:
* The return value is EOF if an error occurred while writing
* to the stream, or if the stream isn't writable. Otherwise
* it's the value of the character written.
*
* Side effects:
* Characters are buffered up for stream.
*
*----------------------------------------------------------------------
*/
int
fputc(c, stream)
char c; /* Character to output. */
register FILE *stream; /* Stream on which to output. */
{
if ((stream->status != 0) || !(stream->flags & STDIO_WRITE)) {
return EOF;
}
/*
* This is tricky because of two things:
* a) The stream could be used both for reading and writing. If
* the last access was a read access, or if the stream has never
* been used for writing, "turn the stream around" before doing
* the write.
* b) The stream may be unbuffered (want to output each character
* as it comes). To handle this, call the writeProc as soon
* as the buffer fills, rather than delaying until a character
* arrives that doesn't fit.
* c) Keep the notion of "writeCount" separate from the notion of
* "all buffer space in use". That way, the stream's I/O mgr
* can arrange for itself to be called anytime it wants (even if
* the buffer isn't full) just by making writeCount 1.
*/
if (stream->writeCount == 0) {
stream->readCount = 0;
stream->lastAccess = stream->buffer - 1;
}
stream->writeCount--;
stream->lastAccess++;
*(stream->lastAccess) = c;
if ((c == '\n') && (stream->flags & STDIO_LINEBUF)) {
(*stream->writeProc)(stream, 1);
} else if (stream->writeCount <= 0) {
(*stream->writeProc)(stream, 0);
}
if (stream->status != 0) {
return EOF;
}
return (unsigned char) c;
}
@
1.2.1.1
log
@Initial branch for Sprite server.
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fputc.c,v 1.2 88/07/21 10:49:10 ouster Exp $ SPRITE (Berkeley)";
@
1.1
log
@Initial revision
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: atoi.c,v 1.1 88/04/28 17:20:23 ouster Exp $ SPRITE (Berkeley)";
d33 2
a34 1
* to the stream, or if the stream isn't writable.
d83 1
a83 1
return 0;
@